﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace NETXPF.Library
{
    /// <summary>
    /// No nonsense persistence of objects based on public properties.
    /// Formats Supported: XML
    /// Formats to be Supported: Binary, ADO.NET Table, JSON
    /// </summary>
    public static class Persist
    {
        public static void ToXML(Stream s, object o)
        {
            XmlSerializer xs = new XmlSerializer(o.GetType());
            xs.Serialize(s, o);
        }
        public static T FromXML<T>(Stream s)
        {
            XmlSerializer xs = new XmlSerializer(typeof(T));
            return (T)xs.Deserialize(s);
        }
        public static void ToJSON(TextWriter tw, object o)
        {
            tw.Write(JSON.JSONify(o));
        }
    }
}
